//
//  YLStatusOriginaView.swift
//  weiBo
//
//  Created by 杨雷 on 2016/12/5.
//  Copyright © 2016年 Yang.L. All rights reserved.
//

import UIKit






//原创View
class YLStatusOriginaView: UIView {
    
    var statusViewModel: YLStatusViewModel?{
        didSet{
            if let imageUrl = statusViewModel?.status?.user?.profile_image_url{
                userImageView.sd_setImage(with: URL(string: imageUrl), placeholderImage:  #imageLiteral(resourceName: "avatar_default_big"))
            }
            
            screenNameLabel.text = statusViewModel?.status?.user?.screen_name
            
            contentLabel.text = statusViewModel?.status?.text
            
            mbrankImageView.image = statusViewModel?.mbrankImage
            
            verifiedTypeImageView.image = statusViewModel?.verifiedTypeImage
            
        }
    }
    
    
    
    //懒加载
    //用户头像
    private lazy var userImageView : UIImageView = UIImageView(image: #imageLiteral(resourceName: "avatar_default_big"))
    //认证等级
    private lazy var verifiedTypeImageView : UIImageView = UIImageView(image: #imageLiteral(resourceName: "avatar_vip"))
    //昵称
    private lazy var screenNameLabel: UILabel = {
        let label = UILabel(font: 14, textColor: UIColor.darkGray)
        label.text = "羊羊羊"
        return label
    }()
    
    //会员等级
    private lazy var mbrankImageView : UIImageView = UIImageView(image: #imageLiteral(resourceName: "common_icon_membership"))
    
    //时间
    private lazy var timeLabel: UILabel = {
        let label = UILabel(font: 12, textColor: UIColor.orange)
        label.text = "刚刚"
        return label
    }()
    
    //来源
    private lazy var sourceLabel: UILabel = {
        let label = UILabel(font: 14, textColor: UIColor.lightGray)
        label.text = "来自东土"
        return label
    }()
    
    //内容
    private lazy var contentLabel: UILabel = {
        let label = UILabel(font: 14, textColor: UIColor.darkGray)  
        label.text = "来自:东土大唐.来自:东土大唐.来自:东土大唐.来自:东土大唐.来自:东土大唐."
        label.backgroundColor = UIColor.cyan
        label.numberOfLines = 0
        return label
    }()
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        backgroundColor = RandomColor()
        
        addSubview(userImageView)
        addSubview(verifiedTypeImageView)
        addSubview(screenNameLabel)
        addSubview(mbrankImageView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(contentLabel)
        
        
        userImageView.snp.makeConstraints { (make) in
            make.top.left.equalTo(self).offset(StatusItemMargin)
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
        
        verifiedTypeImageView.snp.makeConstraints { (make) in
            make.centerX.equalTo(userImageView.snp.right)
            make.centerY.equalTo(userImageView.snp.bottom)
        }
        
        screenNameLabel.snp.makeConstraints { (make) in
            make.left.equalTo(userImageView.snp.right).offset(StatusItemMargin)
            make.top.equalTo(userImageView)
        }
        
        mbrankImageView.snp.makeConstraints { (make) in
            make.left.equalTo(screenNameLabel.snp.right).offset(StatusItemMargin)
            make.top.equalTo(screenNameLabel)
        }
        
        timeLabel.snp.makeConstraints { (make) in
            make.bottom.equalTo(userImageView)
            make.left.equalTo(screenNameLabel)
        }
        
        sourceLabel.snp.makeConstraints { (make) in
            make.left.equalTo(timeLabel.snp.right).offset(StatusItemMargin)
            make.bottom.equalTo(timeLabel)
        }
        
        contentLabel.snp.makeConstraints { (make) in
            make.left.equalTo(userImageView)
            make.top.equalTo(userImageView.snp.bottom).offset(StatusItemMargin)
            make.width.equalTo(screenWidth - 2 * StatusItemMargin)
        }
        
        self.snp.makeConstraints { (make) in
            make.bottom.equalTo(contentLabel.snp.bottom).offset(StatusItemMargin)
        }
        
        
        
        
    }
    

}
